<template>
  <div style="height:100%">
    <breadcrumb :breadList="breadList" :name="name" style="margin-bottom: 12px;" v-if="isShow">
      <div class="handle-box" slot="handleContent">
        <!-- <div class="handle-btn">
          <a-button class="common-btn" >关联用户</a-button>
        </div> -->
        <div class="handle-btn">
          <a-button class="common-btn" @click="submitProMessage">提交</a-button>
        </div>
        <div class="handle-btn">
          <a-button @click="cancel" class="common-btn">取消</a-button>
        </div>
        <!-- <div class="handle-btn" v-if="currentType === 'create'">
          <a-button class="common-btn" @click="connectUser">关联用户</a-button>
        </div>
        <div class="handle-btn" v-if="currentType === 'modify'">
          <a-button class="common-btn" @click="updateUser">修改用户</a-button>
        </div> -->
      </div>
    </breadcrumb>
    <a-card class="card">
      <a-form :form="form">
        <a-row :gutter="16">
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="所属项目" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-input :disabled="disabled" v-decorator="['queryParam.possessive', {initialValue: this.currentPro.possessive, rules: [{required: false, message: ''}]}]" placeholder="" style="width: 270px;"/>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="用户类型" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-select @change="handleChangeType" :disabled="disabled" v-decorator="['queryParam.userType', {initialValue: '1', rules: [{required: false, message: ''}]}]" style="width: 270px;">
                <a-select-option value="1">居民</a-select-option>
                <a-select-option value="2">企业</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-card>
    <a-card class="card" title="用户基本信息" :bordered="false">
      <a-form :form="form">
        <a-row :gutter="16" v-if="currentShowUser">
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="户主姓名" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-input :disabled="disabled" v-decorator="['queryParam.userName', {initialValue: this.currentPro.userName, rules: [{required: false, message: ''}]}]" placeholder="" style="width: 270px;"/>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="身份证号" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-input :disabled="disabled" v-decorator="['queryParam.identity', {initialValue: currentPro.userIdentity, rules: [{required: false, message: ''}]}]" placeholder="" style="width: 270px;"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="16" v-if="currentShowCompany">
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="企事业单位名称" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-input :disabled="disabled" v-decorator="['queryParam.companyName', {initialValue: this.currentPro.companyName, rules: [{required: false, message: ''}]}]" placeholder="" style="width: 270px;"/>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="社会统一信用代码" :labelCol="{lg: {span: 8}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-input :disabled="disabled" v-decorator="['queryParam.identityCode', {initialValue: currentPro.identityCode, rules: [{required: false, message: ''}]}]" placeholder="" style="width: 270px;"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="16">
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="联系人" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-input :disabled="disabled" v-decorator="['queryParam.personName', {initialValue: currentPro.userName, rules: [{required: false, message: ''}]}]" placeholder="" style="width: 270px;"/>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="联系电话" :labelCol="{lg: {span: 8}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-input-number :disabled="disabled" v-decorator="['queryParam.personTel', {initialValue: currentPro.userTel, rules: [{required: false, message: ''}]}]" placeholder="" style="width: 270px;"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="16">
          <a-col :lg="20" :md="12" :sm="24">
            <div class="spec-row">
              <a-form-item class="spec-item" label="房租地址" :labelCol="{lg: {span: 4}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
                <div style="display:flex;">
                  <a-form-item>
                    <a-select :disabled="disabled" v-decorator="['queryParam.provice', {initialValue: '山西省', rules: [{required: false, message: ''}]}]" style="width: 160px;">
                      <a-select-option value="山西省">山西省</a-select-option>
                      <a-select-option value="山东省">山东省</a-select-option>
                    </a-select>
                  </a-form-item>
                  <a-form-item>
                    <a-select :disabled="disabled" v-decorator="['queryParam.municipal', {initialValue: '太原市', rules: [{required: false, message: ''}]}]" style="width: 160px;">
                      <a-select-option value="市">市</a-select-option>
                      <a-select-option value="太原市">太原市</a-select-option>
                      <a-select-option value="未知市">未知市</a-select-option>
                    </a-select>
                  </a-form-item>
                  <a-form-item>
                    <a-select :disabled="disabled" v-decorator="['queryParam.county', {initialValue: '小店区', rules: [{required: false, message: ''}]}]" style="width: 160px;">
                      <a-select-option value="县（区）">县（区）</a-select-option>
                      <a-select-option value="小店区">小店区</a-select-option>
                      <a-select-option value="未知区">未知区</a-select-option>
                    </a-select>
                  </a-form-item>
                  <a-form-item>
                    <a-input v-decorator="['queryParam.details', {initialValue: currentPro.userAddress, rules: [{required: false, message: ''}]}]" placeholder="详细地址" style="width: 285px;"/>
                  </a-form-item>
                </div>
              </a-form-item>
            </div>
          </a-col>
        </a-row>
        <a-row :gutter="16">
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="房屋数量" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-input-number :disabled="disabled" v-decorator="['queryParam.totalCount', {initialValue: currentPro.userRoom, rules: [{required: false, message: ''}]}]" placeholder="" style="width: 270px;"/>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="建筑面积（m²）" :labelCol="{lg: {span: 8}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-input-number :disabled="disabled" v-decorator="['queryParam.totalEara', {initialValue: currentPro.acreage, rules: [{required: false, message: ''}]}]" placeholder="" style="width: 270px;"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="16">
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="清洁取暖途径" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-select :disabled="disabled" v-decorator="['queryParam.proType', {initialValue: 1, rules: [{required: false, message: ''}]}]" style="width: 270px;">
                <a-select-option :value="1">集中供热</a-select-option>
                <a-select-option :value="2">煤改电</a-select-option>
                <a-select-option :value="3">煤改气</a-select-option>
                <a-select-option :value="4">其他</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="备注" :labelCol="{lg: {span: 8}, sm: {span: 7}}" :wrapperCol="{lg: {span: 15}, sm: {span: 17} }">
              <a-textarea rows="1" :disabled="disabled" v-decorator="['queryParam.remark', {initialValue: currentPro.remark, rules: [{required: false, message: ''}]}]" placeholder="" style="width:270px;"/>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-card>
    <a-card class="card" title="资料上传" :bordered="false" v-if="currentShowUser">
      <a-form>
        <a-row :gutter="16">
          <a-col :lg="24" :md="12" :sm="24">
            <a-form-item label="户口本" :labelCol="{lg: {span: 3}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <div style="width:600px;display:flex;" >
                <a-upload
                  v-if="isShow"
                  name="file"
                  :multiple="true"
                  action="//jsonplaceholder.typicode.com/posts/"
                  :headers="headers"
                  @change="handleChange">
                  <a>
                    上传
                  </a>
                </a-upload>
                <a style="margin:0 20px" @click="downLoad">下载</a>
                <a>查看</a>
              </div>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="16">
          <a-col :lg="24" :md="12" :sm="24">
            <a-form-item label="身份证" :labelCol="{lg: {span: 3}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <div style="width:200px;display:flex;" >
                <a-upload
                  v-if="isShow"
                  name="file"
                  :multiple="true"
                  action="//jsonplaceholder.typicode.com/posts/"
                  :headers="headers"
                  @change="handleChange">
                  <a>
                    上传
                  </a>
                </a-upload>
                <a style="margin:0 20px" @click="downLoad">下载</a>
                <a>查看</a>
              </div>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="16">
          <a-col :lg="24" :md="12" :sm="24">
            <a-form-item label="照片" :labelCol="{lg: {span: 3}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <div style="width:200px;display:flex;" >
                <a-upload
                  v-if="isShow"
                  name="file"
                  :multiple="true"
                  action="//jsonplaceholder.typicode.com/posts/"
                  :headers="headers"
                  @change="handleChange">
                  <a>
                    上传
                  </a>
                </a-upload>
                <a style="margin:0 20px" @click="downLoad">下载</a>
                <a>查看</a>
              </div>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="16">
          <a-col :lg="24" :md="12" :sm="24">
            <a-form-item label="其他资料" :labelCol="{lg: {span: 3}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <div style="width:200px;display:flex;" >
                <a-upload
                  v-if="isShow"
                  name="file"
                  :multiple="true"
                  action="//jsonplaceholder.typicode.com/posts/"
                  :headers="headers"
                  @change="handleChange">
                  <a>
                    上传
                  </a>
                </a-upload>
                <a style="margin:0 20px" @click="downLoad">下载</a>
                <a>查看</a>
              </div>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-card>
    <a-card class="card" title="资料上传" :bordered="false" v-if="currentShowCompany">
      <a-form>
        <a-row :gutter="16">
          <a-col :lg="24" :md="12" :sm="24">
            <a-form-item label="营业执照" :labelCol="{lg: {span: 3}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <div style="width:600px;display:flex;" >
                <a-upload
                  v-if="isShow"
                  name="file"
                  :multiple="true"
                  action="//jsonplaceholder.typicode.com/posts/"
                  :headers="headers"
                  @change="handleChange">
                  <a>
                    上传
                  </a>
                </a-upload>
                <a style="margin:0 20px" @click="downLoad">下载</a>
                <a>查看</a>
              </div>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="16">
          <a-col :lg="24" :md="12" :sm="24">
            <a-form-item label="开户许可证" :labelCol="{lg: {span: 3}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <div style="width:200px;display:flex;" >
                <a-upload
                  v-if="isShow"
                  name="file"
                  :multiple="true"
                  action="//jsonplaceholder.typicode.com/posts/"
                  :headers="headers"
                  @change="handleChange">
                  <a>
                    上传
                  </a>
                </a-upload>
                <a style="margin:0 20px" @click="downLoad">下载</a>
                <a>查看</a>
              </div>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="16">
          <a-col :lg="24" :md="12" :sm="24">
            <a-form-item label="其他资料" :labelCol="{lg: {span: 3}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <div style="width:200px;display:flex;" >
                <a-upload
                  v-if="isShow"
                  name="file"
                  :multiple="true"
                  action="//jsonplaceholder.typicode.com/posts/"
                  :headers="headers"
                  @change="handleChange">
                  <a>
                    上传
                  </a>
                </a-upload>
                <a style="margin:0 20px" @click="downLoad">下载</a>
                <a>查看</a>
              </div>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-card>
    <a-card class="card" title="已安装设备" :bordered="false">
      <a-table :columns="columns" :dataSource="loadData" bordered :pagination="false">
      </a-table>
    </a-card>
  </div>
</template>

<script>
import GlobalHeader from '@/components/GlobalHeader'
import Breadcrumb from '@/components/tools/Breadcrumb'
import Cascader from 'ant-design-vue/lib/cascader'
export default {
  name: 'AddProjects',
  components: {
    GlobalHeader,
    Breadcrumb,
    'a-cascader': Cascader
  },
  data () {
    return {
      name: '',
      breadList: [],
      code: '',
      disabled: false,
      isShow: true,
      currentShowUser: true,
      currentShowCompany: false,
      queryParam: {},
      loadData: [],
      form: this.$form.createForm(this),
      currentType: '', // 当前页面所属
      currentPro: {}, // 当前产品详情
      headers: {
        authorization: 'authorization-text'
      },
      // 表头
      columns: [
        {
          title: '供应商',
          dataIndex: 'equipmentSupplier'
        }, {
          title: '品牌',
          dataIndex: 'equipmentBrand'
        }, {
          title: '设备名称',
          dataIndex: 'equipmentName'
        }, {
          title: '设备类型',
          dataIndex: 'equipmentType'
        }, {
          title: '设备型号',
          dataIndex: 'equipmentVersion'
        }, {
          title: '设备参数',
          dataIndex: 'equipmentParameter'
        }, {
          title: '数量',
          dataIndex: 'equipmentNumber'
        }
      ]
    }
  },
  created () {
    this.currentType = this.$route.query.type
    this.currentPro = JSON.parse(this.$route.query.proDetails)
    console.log('当前详情', this.currentType, this.currentPro)
    this.getBreadCrumb()
    if (this.$route.query.type !== 'create' && this.$route.query.type !== 'modify') {
      this.disabled = true
      this.isShow = false
    } else {
      this.disabled = false
      this.isShow = true
    }
    // if (this.type === 'detail') {
    //   this.disabled = true
    //   this.isShow = false
    // } else {
    //   this.disabled = false
    //   this.isShow = true
    // }
    this.getData()
  },
  methods: {
    // 面包屑处理
    getBreadCrumb () {
      this.breadList = []
      this.name = this.$route.name
      this.$route.matched.forEach(item => {
        console.log('1111', item)
        this.breadList.push(item)
      })
      switch (this.$route.query.type) {
        case 'detail':
          this.breadList[2].meta.title = '用户详情'
          break
        case 'modify':
          this.breadList[2].meta.title = '编辑用户'
          break
        case 'approve':
          this.breadList[2].meta.title = '用户详情'
          break
        default:
          this.breadList[2].meta.title = '添加用户'
          break
      }
    },
    onChange (value) {
      console.log(value)
    },
    handleChangeType (value) {
      if (value === '1') {
        this.currentShowUser = true
        this.currentShowCompany = false
      } else {
        this.currentShowUser = false
        this.currentShowCompany = true
      }
    },
    handleChange (info) {
      if (info.file.status !== 'uploading') {
        console.log(info.file, info.fileList)
      }
      if (info.file.status === 'done') {
        this.$message.success(`${info.file.name} 上传成功`)
      } else if (info.file.status === 'error') {
        this.$message.error(`${info.file.name} 上传失败.`)
      }
    },
    cancel () {
      const that = this
      this.$confirm({
        title: '是否确定取消，取消后数据将清空',
        okText: '确认',
        cancelText: '取消',
        onOk () {
          that.$success({
            title: '已取消'
          })
        }
      })
    },
    submitProMessage () {
      const that = this
      this.$confirm({
        title: '确认提交吗',
        okText: '确认',
        cancelText: '取消',
        onOk () {
          that.$success({
            title: '已提交'
          })
        }
      })
    },
    connectUser () {
      this.$warning({
        title: '请输入正确的用户信息'
      })
    },
    updateUser () {
      const that = this
      this.$confirm({
        title: '用户一旦更改立即生效，请确认是否继续更改用户',
        okText: '确认',
        cancelText: '取消',
        onOk () {
          that.$success({
            title: '已提交'
          })
        }
      })
    },
    toSeeCount () {
      this.$warning({
        title: '当前无关联用户'
      })
    },
    downLoad () {
      this.$success({
        title: '下载成功，请本地打开查看'
      })
    },
    addEquipmentDetails () {
      this.$router.push({
        name: 'addEquipmentDetails'
      })
    },
    getData () {
      this.loadData = [
        {
          equipmentSupplier: '美的上海',
          equipmentBrand: '美的',
          equipmentName: '节能省电静音移动地暖烤火浴室电热器',
          equipmentType: '集中供热',
          equipmentVersion: 'HDY22TH_节能款',
          equipmentParameter: '2200W大功率',
          equipmentNumber: '100000'
        }, {
          equipmentSupplier: '美的上海',
          equipmentBrand: '美的',
          equipmentName: '节能省电静音移动地暖烤火浴室电热器',
          equipmentType: '集中供热',
          equipmentVersion: 'HDY22TH_节能款',
          equipmentParameter: '2200W大功率',
          equipmentNumber: '100000'
        }, {
          equipmentSupplier: '美的上海',
          equipmentBrand: '美的',
          equipmentName: '节能省电静音移动地暖烤火浴室电热器',
          equipmentType: '集中供热',
          equipmentVersion: 'HDY22TH_节能款',
          equipmentParameter: '2200W大功率',
          equipmentNumber: '100000'
        }, {
          equipmentSupplier: '美的上海',
          equipmentBrand: '美的',
          equipmentName: '节能省电静音移动地暖烤火浴室电热器',
          equipmentType: '集中供热',
          equipmentVersion: 'HDY22TH_节能款',
          equipmentParameter: '2200W大功率',
          equipmentNumber: '100000'
        }, {
          equipmentSupplier: '美的上海',
          equipmentBrand: '美的',
          equipmentName: '节能省电静音移动地暖烤火浴室电热器',
          equipmentType: '集中供热',
          equipmentVersion: 'HDY22TH_节能款',
          equipmentParameter: '2200W大功率',
          equipmentNumber: '100000'
        }, {
          equipmentSupplier: '美的上海',
          equipmentBrand: '美的',
          equipmentName: '节能省电静音移动地暖烤火浴室电热器',
          equipmentType: '集中供热',
          equipmentVersion: 'HDY22TH_节能款',
          equipmentParameter: '2200W大功率',
          equipmentNumber: '100000'
        }
      ]
    }
  }
}
</script>

<style lang="less" scoped>
.spec-row {
  margin-left: -16px;
}
.spec-item {
  margin-bottom: 0px;
}
.spec-card {
  height: 56px;
}
</style>
